package com.myaxuan.configuration.websocket;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;

/**
 * Created by pc255 on 2018/3/5.
 */

@Configuration
// @EnableWebSocketMessageBroker注解用于开启使用STOMP协议来传输基于代理（MessageBroker）的消息，这时候控制器（controller）
// 开始支持@MessageMapping,就像是使用@requestMapping一样。
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer{

	@Override
	public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
		stompEndpointRegistry.addEndpoint("/endpointWisely").withSockJS();
	}

	@Override
	public void configureMessageBroker(MessageBrokerRegistry registry){
		//服务端发送消息给客户端的域,多个用逗号隔开
		registry.enableSimpleBroker("/topic", "/user");
		//定义一对一推送的时候前缀
		registry.setUserDestinationPrefix("/msg");
		//定义websoket前缀
		registry.setApplicationDestinationPrefixes("/ws-push");
	}
}
